######################################################
#PA 2018 Partisanship Model Figure.
# When Women Run, Voters Will Follow (Sometimes): 
##Examining the Mobilizing Effect of Female Candidates in the 2014 and 2018 Midterm Elections 
#By Safarpour, Wyckoff Gaynor, Rouse, and Swers #
######################################################

#clean the environment.
rm(list=ls()) 

#Packages.
library(ggplot2)
library(cowplot) 

#Setwd.
setwd("/Users/ACS/Dropbox/When Women Run/Revision_PoliticalBehavior/R&R Part 2/Publication Docs/Replication Data and Code/")

#Data.
PA<- read.csv("PA2018GeneralEffectsInteractivePartyRevised.csv", header=TRUE)

#Figure.
pdf("PA2018PartisanshipModelRevised.pdf", width=9, height=5)
MP<-ggplot(d=PA, aes(Registrant.Subgroup, Effect*100))+
  geom_point(position = "dodge",
             stat = "identity")+
  geom_errorbar(aes(ymin=`UpperCI`*100, ymax=`LowerCI`*100),  width=0.5)+
  geom_hline(yintercept=0, linetype="dashed", color="gray28")+
  labs(y="Percentage Point Difference in Predicted \nProbability of Voting", x="")+
  theme_bw()+theme(axis.text=element_text(size=8.5, angle=90), axis.title=element_text(size=10))
ggdraw(add_sub(MP, x=0,hjust=0,
               "Notes: Error bars are 95% confidence intervals calculated using simulation holding covariates at their observed values. Estimates computed using results \nfrom table C.3.", #add note.
               fontface = "italic", colour = "black", size=9)) #x=0.2 shifts it so its left justified.
dev.off()
